<?php
/** 商品详情 */
namespace app\api\controller\v1;

use app\api\model\Product as ProductModel;
use app\api\validate\Count;
use app\api\validate\IDMustBePositiveInt;
use app\lib\exception\ProductException;

class Product{
    //推荐商品
    public function getRecent($count=15){
        (new Count())->goCheck();
        $products=ProductModel::getMostRecent($count);

        if($products->isEmpty()){
            throw new ProductException();
        }
        $products=$products->hidden(['summary']);
        return $products; 
    }

    //分类商品
    public function getAllInCategory($id){
        (new IDMustBePositiveInt())->goCheck();
        $products=ProductModel::getPriductsByCategoryID($id);
        if($products->isEmpty()){
            throw new ProductException();
        }
        $products=$products->hidden(['summary']);
        return $products;
    }

    //获取商品详情页
    public function getOne($id){
        (new IDMustBePositiveInt())->goCheck();
        $product=ProductModel::getProductDetail($id);
        if(!$product){
            throw new ProductException();
        }
        return $product;
    }

    //删除一个商品接口
    public function deleteOne($id){

    }
}
